package cn.cntv.app.ipanda.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by ${user} on 2015/11/14.
 * 使用 mPointView = (PointView)v.findViewById(R.id.pointview);
 *   mPointView.setPointCount(ids.length);
 *   mPointView.setCurrentIndex(pointIndex);
 */
public class PointView extends View {
    private Context mContext;
    private Paint mPaint;
    private int mCurrentIndex;
    private int mAllCount;
    private int startX;
//    private Bitmap selectBitmap,defaultBtimap;
    public PointView(Context context) {
        super(context);
        this.mContext = context;
        mPaint = new Paint();
    }
    public PointView(Context context, AttributeSet paramAttributeSet) {
        super(context, paramAttributeSet);
        this.mContext = context;
        mPaint = new Paint();
    }
//    public void setPointImage(int selectImgResId,int defaultImgResId)
//    {
//        Resources resources =  mContext.getResources();
//        mPaint = new Paint();
////        selectBitmap = Bit
//    }

    /**
     * 设置总的点数
     * @param count
     */
    public void setPointCount(int count)
    {
        mAllCount = count;
    }

    /**
     * 设置当前需要选中的点索引
     * @param index
     */
    public void setCurrentIndex(int index)
    {
        mCurrentIndex = index;
        postInvalidate();
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        startX = canvas.getWidth()/2-mAllCount/2*45;
        for (int i = 0 ; i < mAllCount ; i ++)
        {
            if(i == mCurrentIndex)
            {
                mPaint.setColor(0xff336699);
            }else
            {
                mPaint.setColor(0xffffffff);
            }
            canvas.drawCircle(startX+(i+1)*45,30,15,mPaint);
        }
    }
}
